import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: AliceMana
 * Date: 2022-09-08
 * Time: 19:38
 */
public class TestDemo {

    // https://leetcode.cn/problems/set-mismatch/
    public static int[] findErrorNums(int[] nums) {
        int[] arr = new int[nums.length+1];
        Arrays.fill(arr, 0);
        for (int i = 0; i < nums.length; i++) {
            arr[nums[i]]++;
        }
        int[] ret = new int[2];
        for (int i = 1; i <= arr.length-1; i++) {
            if (arr[i] == 2) {
                ret[0] = i;
            }
            if (arr[i] == 0) {
                ret[1] = i;
            }
        }
        return ret;
    }

    public static void main(String[] args) {
        int[] arr = {1,1};
        int[] arr2 = findErrorNums(arr);
        System.out.println(Arrays.toString(arr2));
    }


    // https://www.nowcoder.com/practice/9f3231a991af4f55b95579b44b7a01ba?tpId=13&tqId=23269&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
    public static int minNumberInRotateArray(int [] array) {
        if (array.length == 0) {
            return 0;
        }
        int left = 0;
        int right = array.length-1;
        if (array[left] > array[left+1]) {
            return array[left+1];
        } else if (array[left] < array[left+1] && array[right] > array[left]) {
            return array[left];
        }
        while (left < right-1) {
            int mid = (left+right) >> 1;
            if (array[left] <= array[mid]) {
                left = mid;
            } else if (array[right] >= array[mid]) {
                right = mid;
            }
        }
        return array[right];
    }

    public static void main2(String[] args) {
        int[] arr = {1,0,1,1,1};
        int ret =minNumberInRotateArray(arr);
        System.out.println(ret);
    }

    // https://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8?tpId=37&&tqId=21320&rp=1&ru=/ta/huawei&qru=/ta/huawei/question-ranking
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int positiveCount = 0;
        int negativeCount = 0;
        double sum = 0.0;
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            if (arr[i] < 0) {
                negativeCount++;
            } else if (arr[i] > 0) {
                sum += arr[i];
                positiveCount++;
            }
        }
        if (positiveCount == 0) {
            System.out.println(negativeCount+" "+0.0);
        } else {
            System.out.printf("%d %.1f", negativeCount, sum / positiveCount);
        }
    }
}
